package com.equipment;

import java.util.NoSuchElementException;

import com.util.EncodingUtil;
/**
 * ESAM还原应答
 * @author liuyadong
 *
 */
public class ESAMReductionResponse {

	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length = ""; // 数据长度
	private String code = "FD"; // 代码
	private String broadening = "D7"; // 扩展代码
	private String status = "";
	private String BCC = ""; // 异或校验值
	/**
	 * 解析D7指令
	 * @param context
	 * @return
	 * @throws NoSuchElementException
	 */
	public ESAMReductionResponse analysis(String context) throws NoSuchElementException  {
		ESAMReductionResponse esamResponse = null;
		if (!context.substring(12, 14).equals("D7")) {
			throw new NoSuchElementException("ESAM还原帧指令错误");
		}
		// 判断是否成功
		if (!context.substring(14, 16).equals("00")) {
			throw new NoSuchElementException("ESMA还原失败:"+EncodingUtil.getErrorResult(EncodingUtil.hexToDec(context.substring(14, 16))));
		}
		try {
			esamResponse = new ESAMReductionResponse();
			esamResponse.status = context.substring(14, 16);

		} catch (Exception e) {
			throw new NoSuchElementException("ESAM还原失败");
		}
		return esamResponse;
	}
	public String getSTX() {
		return STX;
	}
	public void setSTX(String sTX) {
		STX = sTX;
	}
	public String getRSCTL() {
		return RSCTL;
	}
	public void setRSCTL(String rSCTL) {
		RSCTL = rSCTL;
	}
	public String getLength() {
		return Length;
	}
	public void setLength(String length) {
		Length = length;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getBroadening() {
		return broadening;
	}
	public void setBroadening(String broadening) {
		this.broadening = broadening;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getBCC() {
		return BCC;
	}
	public void setBCC(String bCC) {
		BCC = bCC;
	}



}
